package com.ycy.dubbo.controller;

import com.ycy.dubbo.entity.QueryTaskInstsDto;
import com.ycy.dubbo.entity.SearchQuery;
import com.ycy.dubbo.entity.YcyResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 使用 Feign 来调用 服务提供者
 */
@RestController
@RequestMapping("/feign")
public class FeignController {

  Logger logger = LoggerFactory.getLogger(this.getClass());

  @Autowired
  FeignClientInterface feignClientInterface;

  @GetMapping("/time")
  @ResponseBody
  private YcyResponse getTime() {
    Map<String, Object> map = new HashMap<>();
    map.put("i", 1);
    map.put("do", null);
    YcyResponse time = feignClientInterface.getTime(map);
    logger.info("time : {}", time);
    return time;
  }

  @GetMapping("/search")
  private void search() {

    SearchQuery searchQuery = SearchQuery.where("taskEndTime").is(null)
            .and("candiValue").is("1356172011664384002");

    QueryTaskInstsDto queryTaskInstsDto = new QueryTaskInstsDto();
    queryTaskInstsDto.setTaskQuery(searchQuery);

    YcyResponse time = feignClientInterface.getTime(queryTaskInstsDto);
    System.out.println(time);
  }


}
